package cn.ruituo.web;

import cn.ruituo.entity.Page;
import cn.ruituo.entity.Student;
import cn.ruituo.service.StudentService;
import cn.ruituo.util.StrUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "StudentsServlet",value = "/StudentsServlet")
public class StudentsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo= StrUtil.toInt(request.getParameter("pageNo"),1);
        String sname=request.getParameter("sname");
        String qq=request.getParameter("qq");
        String tel=request.getParameter("telephone");
        Page<Student> paging = StudentService.service.paging(pageNo, 20, sname, qq, tel, null, null);
//把这个paging带给jsp,通过上下文对象传递
        request.setAttribute("pageNo",pageNo);
        request.setAttribute("sname",sname);
        request.setAttribute("qq",qq);
        request.setAttribute("telephone",tel);
        request.setAttribute("paging",paging);

        request.getRequestDispatcher("/WEB-INF/views/students2.jsp").forward(request,response);
    }
}
